<?
$DEFAULT_DBSERVER = "localhost";
$DEFAULT_DATABASE = "jbnh";
$DEFAULT_DBUSER = "jbnh";
$DEFAULT_DBPASS = "jbnh!@#$";
$DEFAULT_HOST = "yaedamchea.com";
$LOGIN_FORM_URL = "http://".$DEFAULT_HOST."/login/login.html";
$PUBLIC_PATH    = $_SERVER['DOCUMENT_ROOT']; //  /home/jbnh.shuvic.co.kr/www/html
$FILES_BASE = $_SERVER['DOCUMENT_ROOT'];
$BBS_PATH = "/bbs/";



function DefaultHandleError($errorCode)
{
	echo "오류발생: $errorCode";
	$mysql_error = mysql_error();
	if ($mysql_error)
		echo ": $mysql_error";
	exit;
}

function GetDefaultConnection($database = null)
{
	global $DEFAULT_CONNECTION, $DEFAULT_DATABASE;
	if (!isset($DEFAULT_CONNECTION))
	{
		$DEFAULT_CONNECTION = new MySQLConnection();
		$DEFAULT_CONNECTION->connect();
	}

	if ($database == null)
		$database = $DEFAULT_DATABASE;

	if ($database)
		$DEFAULT_CONNECTION->select_db($database);

	return $DEFAULT_CONNECTION;
}

function GetCurrentUser($options = null)
{
	global $session;
	return $session->getString("userid", "");
}

function GetCurrentUserInfo($options = null)
{
	global $session;
	$userid = $session->getString("userid", "");
	if ($userid)
	{
		return array(
			'userid'				=> $userid,
			'userno'				=> $session->getNumber("userno"),
			'userlvl'				=> $session->getNumber("userlvl"),
		);
	}
	else
		return null;
}

function IsAdmin($options = null)
{
	global $session;
	//userlvl : 1:전체관리자, 2:지역농협관리자, 3:지역관리자
	$isAdmin = false;
	if ( $session->getNumber("userlvl") == 1 )
		$isAdmin = true;
	return $isAdmin;
}

function IsOwner($current_id, $writer_id)
{
	$isOwner = false;
	if ( IsAdmin() )
		$isOwner = true;
	else
		if ( $current_id != null && $writer_id != null && strlen($writer_id) > 0 )
			if (strcasecmp($writer_id, GetCurrentUser()) == 0)
				$isOwner = true;
	return $isOwner;
}


function GetAdminCertify($chk)
{
/*
	lvl
	0:일반회원
	1:관리자

	options
	0:권한체크 안함
	1:권한이 어드민만 있는경우
	2:어드민다음 권한허용
*/
	/*권한 체크
	if ($PHP_SELF =='admin????.php' && $member_level != 2)
	{
		return;
	}
	*/

	global $session;
	$userlvl = $session->getString("userlvl","");
	$userid = $session->getString("userid","");

	if($userlvl == "") {
		if($chk == "1" || $chk == "2")
			jserror("권한이 없습니다.");
		return 1;
	}
	else {
		if($userlvl == "1" )
			return 1;
		else {
			if($chk == "1")
				jserror("권한이 없습니다.");

			//if($chk == "2" && $userlvl != "8")
			//	jserror("권한이 없습니다!.");

			return $userlvl;
		}
	}
}

function getMenuSelect1($str1)
{
	global $menu1;
	if ($menu1==$str1)
		return "_on";
	else
		return "_off";
}
function getMenuSelect2($str1, $str2)
{
	global $menu1, $menu2;
	if ($menu1==$str1 && $menu2==$str2)
		return " class=\"active\" ";
	else
		return "";
}
?>